package com.weirong.smartvault.backservice.entity_model;

import com.weirong.smartvault.backservice.util.common.DateUtil;
import com.weirong.smartvault.backservice.util.common.ListTool;
import com.weirong.smartvault.entity.Role;
import com.weirong.smartvault.backservice.user.IUser;

import java.lang.reflect.InvocationTargetException;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: kfeb4
 * Date: 2017/12/27
 * Time: 20:19
 */
public class RoleModel {
    Role role;

    public RoleModel(Role role) {
        this.role = role;

    }

    public String getName() {
        return role.getName();
    }

    public String getComment() {
        return role.getComment();
    }

    public String getCreatorName() {
        IUser user = IUser.findOne(role.getCreator());
        return user.getUserName();
    }

    public String getCreatTime() {
        return DateUtil.getNomalString(role.getCreatedTime());
    }

    public Integer getId(){
        return role.getId();
    }

    public List<AuthorityModel> getAllAuthority() throws InvocationTargetException, NoSuchMethodException, InstantiationException, IllegalAccessException {
        return ListTool.cast(role.getAuthorities(),AuthorityModel.class);
    }

}
